<?php
class TestAnswers extends CActiveRecord {
	
	public static function model($className = __CLASS__) {
		return parent::model($className);
	}

	public function tableName() {
		return strtolower('PsyTestAnswers');
	}
	
    public function relations() {
        return array(
            'question' => array(self::BELONGS_TO, 'TestQuestions', 'questionId',
                'joinType' => 'INNER JOIN',
            ),
            'mark' => array(self::HAS_MANY, 'TestAnswerMark', 'answerId',
                'joinType' => 'LEFT JOIN',
            ),
            'linkage' => array(self::HAS_ONE, 'TestAnswerLinkage', 'answerId',
                'joinType' => 'LEFT JOIN',
            )
        );
    }

	public function attributeLabels() {
		return array(
			'answer' => '选项描述',
			'answerOrder' => '选项序号'
		);
	}
	
	public function afterDelete() {
		TestAnswerMark::model()->deleteAll('answerId = '.$this->answerId);
		TestAnswerLinkage::model()->deleteAll('answerId = '.$this->answerId);
	}
    
	public function rules() {
		return array(
			array('answer, answerOrder', 'required'),
			array('answerOrder', 'numerical')
		);
	}
}
